package com.ls.fw.data.search.impl.dao.base;

import java.util.Map;

import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.admin.indices.flush.FlushResponse;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.support.broadcast.BroadcastOperationResponse;
import org.elasticsearch.client.AdminClient;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;

public interface ESBaseDao {

	/**
	 * 默认服务名称
	 */
	public static String CLUSTERNAME = "elasticsearch";
	
	public TransportClient getServer();
	
	/**
     * Ensures the cluster has a green state via the cluster health API. This method will also wait for relocations.
     * It is useful to ensure that all action on the cluster have finished and all shards that were currently relocating
     * are now allocated and started.
     */
	public ClusterHealthStatus  ensureGreen(String... indices) ;
    /**
     * Ensures the cluster has a green state via the cluster health API. This method will also wait for relocations.
     * It is useful to ensure that all action on the cluster have finished and all shards that were currently relocating
     * are now allocated and started.
     *
     * @param timeout time out value to set on {@link org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest}
     */
    public ClusterHealthStatus ensureGreen(TimeValue timeout, String... indices) ;

    /**
     * Waits for all relocating shards to become active using the cluster health API.
     */
    public ClusterHealthStatus waitForRelocation() ;

    /**
     * Waits for all relocating shards to become active and the cluster has reached the given health status
     * using the cluster health API.
     */
    public ClusterHealthStatus waitForRelocation(ClusterHealthStatus status) ;

    
    /**
     * Ensures the cluster is in a searchable state for the given indices. This means a searchable copy of each
     * shard is available on the cluster.
     */
    public ClusterHealthStatus ensureSearchable(String... indices) ;
    /**
     * Syntactic sugar for:
     * <pre>
     *   client.prepareIndex(index, type).setSource(source).execute().actionGet();
     * </pre>
     */
    public IndexResponse index(String index, String type, XContentBuilder source) ;

    /**
     * Syntactic sugar for:
     * <pre>
     *   client.prepareIndex(index, type).setSource(source).execute().actionGet();
     * </pre>
     */
    public IndexResponse index(String index, String type, String id, Map<String, Object> source);

    /**
     * Syntactic sugar for:
     * <pre>
     *   client.prepareGet(index, type, id).execute().actionGet();
     * </pre>
     */
    public GetResponse get(String index, String type, String id) ;

    /**
     * Syntactic sugar for:
     * <pre>
     *   return client.prepareIndex(index, type, id).setSource(source).execute().actionGet();
     * </pre>
     */
    public IndexResponse index(String index, String type, String id, XContentBuilder source) ;

    /**
     * Syntactic sugar for:
     * <pre>
     *   return client.prepareIndex(index, type, id).setSource(source).execute().actionGet();
     * </pre>
     */
    public IndexResponse index(String index, String type, String id, Object... source) ;
    /**
     * Syntactic sugar for:
     *
     * <pre>
     *   return client.prepareIndex(index, type, id).setSource(source).execute().actionGet();
     * </pre>
     *
     * where source is a String.
     */
    public IndexResponse index(String index, String type, String id, String source) ;

    /**
     * Waits for relocations and refreshes all indices in the cluster.
     *
     * @see #waitForRelocation()
     */
    public RefreshResponse refresh();
    /**
     * Flushes and refreshes all indices in the cluster
     */
    public void flushAndRefresh() ;

    /**
     * Flushes all indices in the cluster
     */
    public FlushResponse flush() ;

    public FlushResponse flush(boolean ignoreNotAllowed) ;
    
    public void showErrorInfo(BroadcastOperationResponse response);

    /**
     * Returns <code>true</code> iff the given index exists otherwise <code>false</code>
     */
    public boolean indexExists(String index);

    /**
     * Returns a random admin client. This client can either be a node or a transport client pointing to any of
     * the nodes in the cluster.
     */
    public AdminClient admin();
    

    /**
     * Clears the given scroll Ids
     */
    public boolean clearScroll(String... scrollIds) ;
	
	/**
	 * 创建索引库
	 * @author ls
	 * 2014年12月4日下午3:47:19 
	 * @param index
	 * @param aliase
	 * @return
	 */
	public boolean prepareCreate(String index,String aliase);
	
	
	
	
	public boolean addAliase(String index, String aliase);
	
	
	public boolean exist(String index, String aliase);
	
	public boolean removeAliase(String index, String aliase);
	
	public boolean removeAliase(String removeindex, String newindex, String aliase);
}
